<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <%@include file="/res/include/base-head.jsp"%>
	<%@include file="/res/include/jquery-easyui.jsp"%>
	<%@include file="/res/include/umeditor.jsp"%>
	<script type="text/javascript" src="${pageContext.request.contextPath}/res/js/mall/shop.js"></script>
  </head>
  <body>
<div class="form_item topic_add">
   <form id="data-form">
   	<c:if test="${!empty mallShopVo}">
    	<input type="hidden" name="id" value="${mallShopVo.id }"/>
    	<input type="hidden" name="type" value="${mallShopVo.type }"/>
    </c:if>
    <dl>
        <dt>名称：</dt>
        <dd>${mallShopVo.name }</dd>
    </dl>
    <dl>
        <dt>店铺详情：</dt>
        <dd>${mallShopVo.resume }</dd>
    </dl>
    <dl>
        <dt>店铺电话：</dt>
        <dd><input type="text" id="phone" name="phone" value="${mallShopVo.phone }" class="txt grid-15" maxlength="20" /></dd>
    </dl>
    <dl>
        <dt>服务社区：</dt>
        <dd><input type="text" id="extCommunityNames" name="extCommunityNames" value="${mallShopVo.extCommunityNames }" class="txt grid-25" maxlength="32" readonly="readonly" onclick="admin.shop.chooseExtCommunity()"/>本店铺服务的社区</dd>
        <input type="hidden" id="extCommunityIds" name="extCommunityIds" value="${mallShopVo.extCommunityIds }"/>
    </dl>
    <dl>
        <dt>店铺种类：</dt>
        <dd>
            <select name="style" id="shopStyle" onchange="changeShopStyle(this.value)">
        	    <option value="1"
					<c:if test="${mallShopVo != null && mallShopVo.style==1}"> selected="selected"</c:if>
				>邻里店</option>
				<option value="2"
					<c:if test="${mallShopVo != null && mallShopVo.style==2}"> selected="selected"</c:if>
				>社区店铺</option>
				<option value="3"
					<c:if test="${mallShopVo != null && mallShopVo.style==3}"> selected="selected"</c:if>
				>圈圈便利店</option>
			</select>
        </dd>
    </dl>
    <dl>
        <dt>分账比例：</dt>
        <dd><input type="text" id="rate" name="rate" value="${mallShopVo.rate }" class="txt grid-15 easyui-numberbox" min="0.00" max="1" precision="2" data-options="required:true" maxlength="5" /></dd>
    </dl>
    <dl>
        <dt>起送金额：</dt>
        <dd><input type="text" id="deliveryValue" name="deliveryValue" value="${mallShopVo.deliveryValue }" class="txt grid-15 easyui-numberbox" min="0.00" precision="2" data-options="required:true" maxlength="5" /></dd>
    </dl>
    <dl>
        <dt>配送费：</dt>
        <dd><input type="text" id="freight" name="freight" value="${mallShopVo.freight }" class="txt grid-15 easyui-numberbox" min="0.00" precision="2" data-options="required:true" maxlength="5" /></dd>
    </dl>
    
    <dl>
        <dt>商家圈币结算比例：</dt>
        <dd><input type="text" id="quanPayRate" name="quanPayRate" value="${mallShopVo.quanPayRate }" class="txt grid-15 easyui-numberbox" min="0.00" max="1" precision="2" data-options="required:true" maxlength="4" /></dd>
    </dl>
    <dl>
        <dt>平台圈币结算比例：</dt>
        <dd><input type="text" id="qqQuanPayRate" name="qqQuanPayRate" value="${mallShopVo.qqQuanPayRate }" class="txt grid-15 easyui-numberbox" min="0.00" max="1" precision="2" data-options="required:true" maxlength="4" /></dd>
    </dl>
    
    <dl>
        <dt>主营类目：</dt>
        <dd><input type="text" id="categoryName" value="${mallShopVo.categoryName }" class="txt grid-25" maxlength="32" readonly="readonly" onclick="admin.shop.chooseCategory()"/></dd>
        <input type="hidden" id="categoryId" name="categoryId" value="${mallShopVo.categoryId }"/>
    </dl>
    <dl id="license">
    	<dt>营业执照：</dt>
        <dd>
        	<ul class="product_imglist lp_img">
        	    <c:choose>
	        	<c:when test="${!empty mallShopVo && !empty mallShopVo.licensePic}">
		        	<li>
        			<a href="javascript:;" class="item" id="licensePic" onclick="admin.shop.addImg('licensePic')"><p class="img"><img src="http://file.xfquanquan.com${mallShopVo.licensePic }" alt="" /></p></a>
        			<em onclick="delLicensePic(this)"></em>
        			</li>
	        	</c:when>
	        	<c:otherwise>
	        		<li><a href="javascript:;" class="item" id="licensePic" onclick="admin.shop.addImg('licensePic')">添加图片</a></li>
	        	</c:otherwise>
	        	</c:choose>
         </ul>
        </dd>
    </dl>
    <dl>
    	<dt>配送类型：</dt>
        <dd>
        	<span class="check_txt" id="type1">
         		<input name="sendDeliveryTypeArray" id="buyerPickUp" type="checkbox" value="1" /><label>买家自提</label>
         	</span>
         	<span class="check_txt" id="type2">
         		<input name="sendDeliveryTypeArray" id="sellerSend" type="checkbox" value="2" /><label>商家配送</label>
         	</span>
         	<span class="check_txt" id="type3">
         		<input name="sendDeliveryTypeArray" id="qquanSend" type="checkbox" value="3" /><label>圈圈配送</label>
         	</span>
        </dd>
    </dl>
    </form>
    <p class="page_btn"><input type="button" id="doSave" value="保存" class="btn_blue" onclick="doSave();"/></p>
</div>
<script type="text/javascript">
$(document).ready(function() {
	<c:if test="${!empty mallShopVo}">
		if('${mallShopVo.style}' == 1){//邻里店
			$('#license').hide();
			$('#type3').hide();
		}else if('${mallShopVo.style}' == 3){//便利店
			$('#type2').hide();
		}
		var sendDeliveryTypeArray = '${mallShopVo.sendDeliveryType}';
        if(sendDeliveryTypeArray.indexOf("1") > -1){
        	$("#buyerPickUp").attr("checked",true);
        }
        if(sendDeliveryTypeArray.indexOf("2") > -1){
        	$("#sellerSend").attr("checked",true);
        }
        if(sendDeliveryTypeArray.indexOf("3") > -1){
        	$("#qquanSend").attr("checked",true);
        }
	</c:if>
});
function changeShopStyle(style){
	if(style == 2){//社区店铺
		$('#type2').show();
		$('#type3').show();
		$('#license').show();
	}else if(style == 1){//邻里店 无圈圈配送、无需营业执照
		$('#type3').hide();
		$('#license').hide();
		$("#qquanSend").attr("checked",false);
	}else if(style == 3){//便利店 无商家配送
		$('#type3').show();
		$('#type2').hide();
		$('#license').show();
		$("#sellerSend").attr("checked",false);
	}
}

var isSave = false;
//提交保存
function doSave(){
	var licensePic = "";
	var licensePicList = $(".lp_img img");
	if (licensePicList && licensePicList.length > 0) {
		licensePicList.each(function(){
		    if (licensePic == "") {
		    	licensePic += $(this).attr("src").replace(imgFilePath,"");
		    } else {
		    	licensePic += ";" + $(this).attr("src").replace(imgFilePath,"");
		    }
		});
	} 
	
	var url = contextPath+'/mall/shop/add';
	<c:if test="${!empty mallShopVo}">
		url = contextPath+'/mall/shop/update';
	</c:if>
	if(!$('#data-form').form('validate')) return;
	if (isSave) {
		return;
	}
	isSave = true;
	var data = $('#data-form').form('jsonObject');
	//营业执照
	data.licensePic = licensePic;
	//配送类型
	var sendDeliveryTypeArray =[];
	$('input[name="sendDeliveryTypeArray"]:checked').each(function(){
		sendDeliveryTypeArray.push($(this).val());
	}); 
	if(sendDeliveryTypeArray.length > 0){
		data.sendDeliveryType = sendDeliveryTypeArray.join(";");
	}else{
		top.showInfo('请选择配送类型');
		return;
	}
	
	$.post(url,data,function(result) {
		if(result.code==1) {
			top.showInfo('保存成功');
		} else {
			isSave = false;
			top.showInfo('保存失败:'+result.msg);
		}
	},'json');
}

function delLicensePic(obj,index){
	$(obj).closest('li').html('<a href="javascript:;" class="item" id="licensePic" onclick="admin.shop.addImg(\'licensePic\')">添加图片</a>');
}
</script>
  </body>
</html>
